Everything Totally Explained


Ask & we'll explain, totally!
Document Type Definition
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


View this entry using RSS

Everything about Document Type Definition totally explained

Document Type Definition (DTD) is one of several SGML and XML schema languages, and is also the term used to describe a document or portion thereof that's authored in the DTD language. A DTD is primarily used for the expression of a schema via a set of declarations that conform to a particular markup syntax and that describe a class, or type, of document, in terms of constraints on the structure of that document. A DTD may also declare constructs that are not always required to establish document structure, but that may affect the interpretation of some documents. XML documents are described using a subset of DTD which imposes a number of restrictions on the document's structure, as required per the XML standard (XML is in itself an application of SGML optimized for automated parsing). DTD is native to the SGML and XML specifications, and since its introduction other specification languages such as XML Schema and RELAX NG have been released with additional functionality.
   As an expression of a schema, a DTD specifies, in effect, the syntax of an "application" of SGML or XML, such as the derivative language HTML or XHTML. This syntax is usually a less general form of the syntax of SGML or XML.
   In a DTD, the structure of a class of documents is described via element and attribute-list declarations. Element declarations name the allowable set of elements within the document, and specify whether and how declared elements and runs of character data may be contained within each element. Attribute-list declarations name the allowable set of attributes for each declared element, including the type of each attribute value, if not an explicit set of valid value(s).

Associating DTDs with documents

A DTD is associated with an XML document via a Document Type Declaration, which is a tag that appears near the start of the XML document. The declaration establishes that the document is an instance of the type defined by the referenced DTD.
   The declarations in a DTD are divided into an internal subset and an external subset. The declarations in the internal subset are embedded in the Document Type Declaration in the document itself. The declarations in the external subset are located in a separate text file. The external subset may be referenced via a public identifier and/or a system identifier. Programs for reading documents may not be required to read the external subset.

Examples

Here is an example of a Document Type Declaration containing both public and system identifiers:
]> ]> All HTML 4.01 documents are expected to conform to one of three SGML DTDs. The public identifiers of these DTDs are constant and are as follows:
The system identifiers of these DTDs, if present in the Document Type Declaration, will be URI references. System identifiers can vary, but are expected to point to a specific set of declarations in a resolvable location. SGML allows for public identifiers to be mapped to system identifiers in catalogs that are optionally made available to the URI resolvers used by document parsing software.

XML DTDs and schema validation

The XML DTD syntax is one of several XML schema languages.
   A common misconception is that non-validating XML parsers are not required to read DTDs, when in fact, the DTD must still be scanned for correct syntax as well as for declarations of entities and default attributes. A non-validating parser may, however, elect not to read external entities, including the external subset of the DTD. If the XML document depends on declarations found only in external entities, it should assert standalone="no" in its XML declaration.

Differences between SGML and XML DTD syntax

The syntax of SGML and XML DTDs are very similar, but not identical.
  • XML DTD Example

    An example of a very simple XML DTD to describe a list of persons is given below:
    Taking this line by line, it says:
  • people_list is a valid element name, and an instance of such an element contains any number of person elements. The * denotes there can be 0 or more person elements within the people_list element.
  • person is a valid element name, and an instance of such an element contains one element named name, followed by one named birthdate (optional), then gender (also optional) and socialsecuritynumber (also optional). The ? indicates that an element is optional. The reference to the name element name has no ?, so a person element must contain a name element.
  • name is a valid element name, and an instance of such an element contains "parsed character data" (#PCDATA).
  • birthdate is a valid element name, and an instance of such an element contains character data.
  • gender is a valid element name, and an instance of such an element contains character data.
  • socialsecuritynumber is a valid element name, and an instance of such an element contains character data. An example of an XML file which makes use of and conforms to this DTD follows. It assumes the DTD is identifiable by the relative URI reference "example.dtd", and the "people_list" after "!DOCTYPE" tells us that the root tags, or the first element defined in the DTD, is called "people_list":
    Fred Bloggs 27/11/2008 Male It is possible to render this in an XML-enabled browser (such as IE5 or Mozilla) by pasting and saving the DTD component above to a text file named example.dtd and the XML file to a differently-named text file, and opening the XML file with the browser. The files should both be saved in the same directory. However, many browsers don't check that an XML document conforms to the rules in the DTD; they're only required to check that the DTD is syntactically correct. For security reasons, they may also choose not to read the external DTD.

    DTD criticisms and alternatives

    While DTD support in XML tools is widespread due to its inclusion in the XML 1.0 standard, it's seen as limiting for the following reasons:
  • No support for newer features of XML — most importantly, namespaces.
  • Lack of expressivity. Certain formal aspects of an XML document can't be captured in a DTD.
  • Custom non-XML syntax to describe the schema, inherited from SGML. (namely 'Extended Backus Naur Form') Three newer XML schema languages that are much more powerful are increasingly favored over DTDs:
  • XML Schema, also referred to as XML Schema Definition (XSD), has achieved Recommendation status within the W3C.
  • RELAX NG, which is also a part of DSDL, is an ISO international standard.
  • Document Structure Description (DSD), attempts to combine an expressive schema balanced with ease of use.Further Information

    Get more info on 'Document Type Definition'.


    External Link Exchanges

    Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

      <a href="http://document_type_definition.totallyexplained.com">Document Type Definition Totally Explained</a>

    Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
       As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



  • Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
    This article contains text from the Wikipedia article Document Type Definition (History) and is released under the GFDL | RSS Version